﻿using Asset.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using zichan.BLL;
using zichan.Entity;

namespace zichan.Controllers
{
    public class CommonController : Controller
    {

        // 验证码
        // GET: Admin/Common
        public virtual ActionResult VerifyImage()
        {
            var validateCodeType = new ValidateCode_Style10();
            string code = "6666";
            byte[] bytes = validateCodeType.CreateImage(out code);
            Session["admin_code"] = code.ToLower();

            return File(bytes, @"image/jpeg");
        }
        public ActionResult MessagePage(int id)
        {
            zichan.Entity.Asset model = AssetService.Get(id);
            model.consumateInfo = ConsumateInfoService.GetList(id);
            return PartialView(model);
        }
        public ActionResult part_Message(int id)
        {
            List<ConsumateInfo> list = new List<ConsumateInfo>();
            list = ConsumateInfoService.GetList(id);
            return PartialView(list);
        }
        public ActionResult partServer_Message(int id)
        {
            ServerInfo model = ServerInfoService.Get(id);
            ViewBag.Staffs = new SelectList(StaffService.StaffAll(1), "ID", "Name", model.AdminiStratorId);
            ViewBag.id = id;
            if (model.AdminiStratorId.HasValue)
                model.AdminiStratorName = StaffService.Get(model.AdminiStratorId.Value).Name;
            return PartialView(model);
        }
        public ActionResult part_PutAway(int cabinetId)
        {
            int number;
            int noUse;
            CabinetManageService.U_Number(out number, out noUse, cabinetId);
            zichan.Models.CabinetNOModel model = new Models.CabinetNOModel();
            model.allNO = number;
            model.subNO = noUse;
            return PartialView(model);
        }
        public ActionResult part_cabinet(int machineRoomId)
        {
            ViewBag.cabinetIds = new SelectList(CabinetManageService.CabinetList(machineRoomId), "Id", "Name");
            return PartialView();
        }
        public ActionResult part_useNO(/*int cabinetId,int? No*/string code)
        {
            //ViewBag.uNOs = new SelectList(CabinetManageService.useNO(cabinetId),No);
            Models.useNOModel model = new Models.useNOModel();
            model.UseNO = ServerInfoService.Get(code);
            return PartialView(model);
        }
        public ActionResult OutOfRock_Part(int id)
        {
            PutawayServer server = CabinetManageService.Get(id);
            Models.DetailModel model = new Models.DetailModel();
            model.cabinet = CabinetManageService.GetCabinet(server.CabinetId);
            model.statu = server.Statu;
            model.noUse = server.Vacancy.Value;
            model.Id = server.Id;
            model.cabinetId = server.CabinetId;
            model.cabinet.MachineRoomName = MachineRoomService.Get(server.MachineRoomId).Name;
            return PartialView(model);
        }
        public ActionResult part_Detail(int id)
        {
            Models.ServerAndFieldsModel model = new Models.ServerAndFieldsModel();
            model.Server = CabinetManageService.Get(id);
            model.Server.CompanyName = CompanyClassService.GetCompany(model.Server.CompanyId.Value).Name;
            if (model.Server.serverPurposeId.HasValue)
                model.Server.serverPurposeName = ServerPurposeService.Get(model.Server.serverPurposeId.Value).serverPurposeName;
            if (model.Server.serverPurposeSubId.HasValue)
                model.Server.serverPurposeSubName = ServerPurposeSubClassService.Get(model.Server.serverPurposeSubId.Value).serverPurposeSubName;
            model.Server.IP = IPService.Get(model.Server.IPId.Value).Ip;
            List<string> ips = new List<string>();
            model.Server.SubIps = IPService.List(model.Server.SubIPIds);
            int serverInfoId = Convert.ToInt32(model.Server.Code.Substring(model.Server.Code.Length - 4, 4));
            model.serverInfo = ServerInfoService.Get(serverInfoId);
            if (!string.IsNullOrEmpty(model.Server.Property))
            {
                model.Server.Code = model.Server.Code + "-" + model.Server.Property;
            }
            return PartialView(model);
        }
        public ActionResult part_Code(int? id, int companyId)
        {
            if (!id.HasValue)
                ViewBag.Codes = new SelectList(AssetService.codeList(companyId));
            if (id.HasValue)
                ViewBag.Codes = new SelectList(AssetService.codeList(id.Value, companyId));
            return PartialView();
        }
        public ActionResult part_SubIp(int machineRoomId, int ipId)
        {
            ViewBag.subIpIds = new SelectList(IPService.NoUseList(machineRoomId, ipId), "Id", "Ip");
            return PartialView();
        }
        public ActionResult part_Ip(int? id, int machineRoomId)
        {
            ViewBag.mRoomId = machineRoomId;
            ViewBag.ipIds = new SelectList(IPService.List(id, machineRoomId), "Id", "Ip");
            return PartialView();
        }
        public ActionResult part_serverSubPurpose(int purposeId)
        {
            ViewBag.serverPurposeSubIds = new SelectList(ServerPurposeSubClassService.GetList(purposeId), "serverPurposeSubId", "serverPurposeSubName");
            //ServerPurposeSubClass c = ServerPurposeSubClassService.Get(1);
            //List<SelectListItem> citems = new List<SelectListItem> { new SelectListItem { Value = c.IsSendProperty, Text = "送产权" }, new SelectListItem { Value = c.IsNoProperty, Text = "无产权" } };
            //ViewBag.Propertys = new SelectList(citems, "Value", "Text");
            ////CabinetClass Tc = CabinetClassService.GetCabinetClass(2);
            //ServerPurposeSubClass Tc = ServerPurposeSubClassService.Get(2);
            //List<SelectListItem> Tcitems = new List<SelectListItem> { new SelectListItem { Value = Tc.IsSendProperty, Text = "送产权" }, new SelectListItem { Value = Tc.IsNoProperty, Text = "无产权" } };
            //ViewBag.TPropertys = new SelectList(Tcitems, "Value", "Text");
            return PartialView();
        }
        #region //可删
        public ActionResult oldpart_Code(int? id, int companyId)
        {
            if (!id.HasValue)
                ViewBag.Codes = new SelectList(AssetService.ServerList(companyId), "Id", "Name");
            if (id.HasValue)
                ViewBag.Codes = new SelectList(AssetService.ServerList(id.Value, companyId), "Id", "Name");
            return PartialView();
        }
        public ActionResult oldpart_useNO(int assetId)
        {
            //ViewBag.uNOs = new SelectList(CabinetManageService.useNO(cabinetId),No);
            Models.useNOModel model = new Models.useNOModel();
            model.UseNO = ServerInfoService.Get(assetId).U_Number;
            return PartialView(model);
        }

        #endregion
    }
}